import 'package:flutter/material.dart';
import 'package:flutter_colorpicker/flutter_colorpicker.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:styled_widget/styled_widget.dart';

import '../controller/drawing_board_controller.dart';

/// 颜色选择器
class ColorPickerWidget extends StatelessWidget {
  const ColorPickerWidget({super.key});

  @override
  Widget build(BuildContext context) {
    return Icon(Icons.color_lens, color: Colors.black87, size: 30.r).gestures(
        onTap: () {
      _showDialog();
    });
  }

  void _showDialog() {
    SmartDialog.show(
      alignment: Alignment.center,
      builder: (_) => _colorPicker(),
    );
  }

  MaterialPicker _colorPicker() {
    return MaterialPicker(
      pickerColor: Colors.amber,
      onColorChanged: (Color value) {
        final dbc = Get.find<DrawingBoardController>();
        dbc.setColor(value);
      },
      enableLabel: false,
      portraitOnly: false,
    );
  }
}
